package com.example.matrix.matrixdemo;

import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author chenxuanwen
 * @Date: 2022/7/25  21:40
 */
@RestController
public class DController {
    /*
 1. 获取单个路径片段中的参数
 请求URI为 /Demo2/66;color=red;year=2020
*/
    @RequestMapping(path="/Demo1/{id}", method=RequestMethod.GET)
    public String test1(@PathVariable String id, @MatrixVariable String color, @MatrixVariable String year){
        return "a";
    }
    /*
     2. 获取单个路径片段中的参数
     请求URI为 /Demo2/color=red;year=2020
    */
    /*@RequestMapping(path="/Demo1/{id}", method=RequestMethod.GET)
    public String test2(@MatrixVariable String color, @MatrixVariable String year){
        return "a";
    }*/


    /*
     3. 获取不同路径片段中的参数
     请求URI为 /Demo2/66;color=red;year=2020/pets/77;color=blue;year=2019
    */
    @RequestMapping(path="/Demo2/{id1}/pets/{id2}", method= RequestMethod.GET)
    public String test3(@PathVariable String id1, @PathVariable String id2,
                        @MatrixVariable(name="color", pathVar="id1") String color1, @MatrixVariable(name="year", pathVar="id1") String year1,
                        @MatrixVariable(name="color", pathVar="id2") String color2, @MatrixVariable(name="year", pathVar="id2") String year2){
        return "a";

    }/*
    *//*
     4. 获取不同路径片段中的参数
     请求URI为 /Demo2/color=red;year=2020/pets/77;color=blue;year=2019
    *//*
    @RequestMapping(path="/Demo2/{id1}/pets/{id2}", method=RequestMethod.GET)
    public String test4(@PathVariable String id2,
                        @MatrixVariable(name="color", pathVar="id1") String color1, @MatrixVariable(name="year", pathVar="id1") String year1,
                        @MatrixVariable(name="color", pathVar="id2") String color2, @MatrixVariable(name="year", pathVar="id2") String year2){
        return "a";

    }*/

    /*
     5. 通过Map获取所有或指定路径下的所有参数
    */
    @RequestMapping(path="/Demo3/{id1}/pets/{id2}", method=RequestMethod.GET)
    public String test5(@MatrixVariable Map<String, Object> all, @MatrixVariable(pathVar="id1") Map<String, Object> mapId1) {
        return "a";
    }
}
